package com.blb.day20231107login.controller;

import com.blb.day20231107login.entity.Permission;
import com.blb.day20231107login.entity.ResponseResult;
import com.blb.day20231107login.entity.Role;
import com.blb.day20231107login.service.IPermissionService;
import com.blb.day20231107login.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @GetMapping("/permissions-children")
    public ResponseResult<List<Permission>> findAll(){
        List<Permission> permissions = permissionService.getPermissionWithChildren();
        return ResponseResult.ok(permissions);
    }

    /**
     * 通过角色id查权限id
     * @param roleId
     * @return
     */
    @GetMapping("/permission-ids/{roleId}")
    public ResponseResult<List<Long>> findPermissionIds(@PathVariable Long roleId){
        List<Long> permissions = permissionService.getselectPermissionIdsByRoleId(roleId);
        return ResponseResult.ok(permissions);
    }
}
